import axios from "axios";
import router from "@/router";
import { message } from "ant-design-vue";

axios.defaults.headers.common["Request-Type"] = "ajax";
// 添加响应拦截器
axios.interceptors.response.use(
  (response) => {
    // 对响应数据做点什么
    let { code } = response.data || {};
    if (code === 401 && !router.currentRoute.value.path.includes("login")) {
      message.error("未登录");
      sessionStorage.removeItem("userInfo");
      router.push({ name: "LoginPage" });
      return Promise.reject(response);
    }
    return response;
  },
  (error) => {
    return Promise.reject(error);
  }
);
export default axios;
